package com.shop.technicalservice.dao.shop.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.shop.ShoptypeDao;
import com.shop.technicalservice.model.shop.Shoptype;

/**
 * A data access object (DAO) providing persistence and search support for
 * Shoptype entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see org.rjb.pojo.ShoptypeDto
 * @author MyEclipse Persistence Tools
 */

public class ShoptypeDaoImpl extends HibernateDaoSupport implements ShoptypeDao{
	private static final Log log = LogFactory.getLog(ShoptypeDaoImpl.class);
	// property constants
	public static final String NAME = "name";

	protected void initDao() {
		// do nothing
	}

	public Shoptype save(Shoptype transientInstance)  throws Exception{
		log.debug("saving Shoptype instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		return transientInstance;
	}

	public void delete(Shoptype persistentInstance)  throws Exception{
		log.debug("deleting Shoptype instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
	}

	public Shoptype findById(java.lang.Integer id)  throws Exception{
		log.debug("getting Shoptype instance with id: " + id);
			Shoptype instance = (Shoptype) getHibernateTemplate().get(
					"org.rjb.Shoptype", id);
			return instance;
	}

	public List findByExample(Shoptype instance)  throws Exception{
		log.debug("finding Shoptype instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value)  throws Exception{
		log.debug("finding Shoptype instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Shoptype as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByName(Object name)  throws Exception{
		return findByProperty(NAME, name);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Shoptype instances");
			String queryString = "from Shoptype";
			return getHibernateTemplate().find(queryString);
	}

	public Shoptype merge(Shoptype detachedInstance)  throws Exception{
		log.debug("merging Shoptype instance");
			Shoptype result = (Shoptype) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Shoptype instance)  throws Exception{
		log.debug("attaching dirty Shoptype instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Shoptype instance)  throws Exception{
		log.debug("attaching clean Shoptype instance");
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
	}

	public static ShoptypeDaoImpl getFromApplicationContext(ApplicationContext ctx) {
		return (ShoptypeDaoImpl) ctx.getBean("ShoptypeDAO");
	}
}